<!DOCTYPE html>
<html class="loading" lang="en" data-textdirection="ltr" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <meta name="author" content="PIXINVENT">
    <title>自助售货管理后台</title>
    <link rel="stylesheet" type="text/css" href="app-assets/css/vendors.css">
    <link rel="stylesheet" type="text/css" href="app-assets/css/vertical-menu.css">
    <link rel="stylesheet" type="text/css" href="app-assets/css/bootstrap-extended.css">
</head>

<body>
<div class="content-wrapper">
    <div class="content-header ">
        <div class="content-header-left mb-2 ">

            <h3 class="content-header-title mb-0">员工考勤详情 </h3>

        </div>
    </div>

    <div class="card">
        <div class="card-content">
            <div class="card-body">
                <div class="searchbox">
                    <form class="form-inline" th:action="@{/attendance_management}" th:object="${attendance}"
                          method="get">
                        <div class="form-group">
                            <input type="text" class="form-control" th:field="*{employeeName}" placeholder="请输入员工名称">
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn btn-primary">查询</button>
                        </div>
                    </form>
                    <div class="form-group">
                        <button type="submit" class="btn btn-success" onclick="add()">新增</button>
                    </div>
                </div>
                <div class="tablebox1">
                    <div style="height: 74vh;overflow: scroll;">
                        <table class="table">
                            <thead>
                            <tr>
                                <th>出勤编号</th>
                                <th>员工编号</th>
                                <th>员工名称</th>
                                <th>职务</th>
                                <th>部门</th>
                                <th>考勤日期</th>
                                <th>上班时间</th>
                                <th>下班时间</th>
                                <th>是否迟到</th>
                                <th>是否早退</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr th:each="el : ${pageInfo.getList()}">
                                <td th:text="${el.attendanceId}"></td>
                                <td th:text="${el.employeeId}"></td>
                                <td th:text="${el.employeeName}"></td>
                                <td th:text="${el.postName}"></td>
                                <td th:text="${el.departmentName}"></td>
                                <td th:text="${#dates.format(el.checkTime,'yyyy-MM-dd')}"></td>
                                <td th:text="${#dates.format(el.checkTime,'yyyy-MM-dd HH:mm:ss')}"></td>
                                <td th:text="${#dates.format(el.singOutTime,'yyyy-MM-dd HH:mm:ss')}"></td>
                                <th th:text="${el.lateOrNot == 0 ? '迟到':'正常'}"></th>

                                <td th:text="${el.lateOrNot == 0 ? '早退' : '正常'}"></td>
                                <td>
                                    <a href="#" class="btn btn-primary btn-td" th:data-id="${el.attendanceId}"
                                       onclick="edit(this.getAttribute('data-id'))">修改</a>
                                    <a href="#" class="btn btn-danger btn-td" th:del-id="${el.attendanceId}"
                                       onclick="del(this.getAttribute('del-id'))">删除</a>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="page clearfix">
                        <div class="pull-left"
                             th:text="|共  ${pageInfo.getTotal()} 条记录 第 ${pageInfo.getPageNum()} / ${pageInfo.getPages()} 页|"></div>
                        <div class="pull-right">

                            <nav aria-label="..." class="pull-left">
                                <ul class="pagination" th:each=" el : ${pageInfo.getNavigatepageNums()}"
                                    th:switch="${el}">
<!--                                    <li class="disabled"><a href="#" aria-label="Previous"><span-->
<!--                                            aria-hidden="true">«</span></a></li>-->
<!--                                    <li th:case="1" class="active"><a-->
<!--                                            th:href="@{'/attendance_management?pageSize=' + ${el}}" th:text="${el}"></a>-->
<!--                                    </li>-->
                                    <li th:case="*"><a th:href="@{'/attendance_management?pageSize=' + ${el}}"
                                                       th:text="${el}"></a></li>
<!--                                    <li><a href="#" aria-label="Next"><span aria-hidden="true">»</span></a></li>-->
                                </ul>
                            </nav>

                            <div class="pull-left p-r-20  p-l-20"><select class="form-control">
                                <option>5条每页</option>
                            </select></div>
                            <div class="pull-left">跳至<input type="text" value="1" class="form-control">页</div>
                        </div>

                    </div>

                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title1" id="modal-title1"> 修改用户信息</h4>
                </div>
                <from id="myForm" name="myForm">
                    <div class="modal-body">
                        <div class="form1 from2">
                            <ul class="row">
                                <li class="col-xs-10">
                                    <span>员工编号：</span>
                                    <input type="number" class="form-control" name="name" id="edit_employeeId" value="">
                                </li>
                                <li class="col-xs-10">
                                    <span>上班时间：</span>
                                    <input type="datetime-local" class="form-control" id="edit_checkTime" value="">
                                </li>
                                <li class="col-xs-10">
                                    <span>下班时间：</span>
                                    <input type="datetime-local" class="form-control" id="edit_singOutTime" value="">
                                </li>
                                <li class="col-xs-10">
                                    <span>是否迟到：</span>
                                    <input type="number" class="form-control" id="edit_lateOrNot" value="">
                                </li>                                <li class="col-xs-10">
                                    <span>是否早退：</span>
                                    <input type="number" class="form-control" id="edit_leaveEarlyOrNot" value="">
                                </li>
                            </ul>
                            <input type="number" class="form-control" style="display: none;" id="edit_attendanceId" value="">
                        </div>
                    </div>
                </from>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="save()">保存</button>
                </div>
            </div>
        </div>
    </div>

</div>

<script src="app-assets/js/vendors.min.js" type="text/javascript"></script>
<script src="app-assets/js/app-menu.js" type="text/javascript"></script>
<script src="app-assets/js/app.js" type="text/javascript"></script>
<script src="app-assets/js/echarts.min.js" type="text/javascript"></script>
<script th:inline="javascript">

    $(document).ready(function () {
        $(".ewm").click(function () {
            $(this).toggleClass("active")
        });
    });

    function add() {
        document.getElementById('modal-title1').innerText = '新增用户信息'
        document.getElementById('edit_employeeId').value = ''
        document.getElementById('edit_checkTime').value = ''
        document.getElementById('edit_singOutTime').value = ''
        document.getElementById('edit_lateOrNot').value = ''
        document.getElementById('edit_leaveEarlyOrNot').value = ''
        document.getElementById('edit_attendanceId').innerText = ''
        $('#myModal').modal('show')
        // $.post('attendance_management/save', {}, function (e, d) {
        //   console.log(e,d)
        // });
    }

    function save() {
        let params = {
            employeeId: document.getElementById('edit_employeeId').value,
            checkTime: document.getElementById('edit_singOutTime').value,
            singOutTime: document.getElementById('edit_singOutTime').value,
            lateOrNot: document.getElementById('edit_lateOrNot').value,
            leaveEarlyOrNot: document.getElementById('edit_leaveEarlyOrNot').value,
            attendanceId: document.getElementById('edit_attendanceId').innerText,
        }
        console.log(params.attendanceId)
        if (params.attendanceId === null || params.attendanceId === '' ||  params.attendanceId === undefined) {
            $.post('attendance_management/insert', params, function (e, d) {
                $('#myModal').modal('hide')
                location.reload();
            });
        } else {
            console.log("更新")
            $.post('attendance_management/update', params, function (e, d) {
                $('#myModal').modal('hide')
                location.reload();
            });
        }

    }


    function edit(id) {
        document.getElementById('modal-title1').innerText = '修改用户信息'
        $.get('/attendance_management/selectById/' + id, function (e, d) {
            document.getElementById('edit_employeeId').value = e.employeeId
            document.getElementById('edit_checkTime').value = e.checkTime
            document.getElementById('edit_singOutTime').value = e.singOutTime
            document.getElementById('edit_lateOrNot').value = e.lateOrNot
            document.getElementById('edit_leaveEarlyOrNot').value = e.leaveEarlyOrNot
            document.getElementById('edit_attendanceId').innerText = e.attendanceId
            $('#myModal').modal('show')
        })
    }

    function del(id) {
        var x;
        var r = confirm("请确认是否删除该数据！");
        if (r === true) {
            $.get('/attendance_management/delete/' + id, function (e, d) {
                location.reload();
            })
        }
    }

</script>
</body>
</html>
